/*
    Copyright(C) 2010 Ying-Chun Liu(PaulLiu). All rights reserved.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package org.debian.paulliu.plft;

import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.awt.datatransfer.*;
import java.awt.image.*;
import java.applet.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;

public class PLFT
{
    public static void log (java.util.logging.Level level, String msg)
    {
	java.lang.StringBuffer strbuf = new StringBuffer();
	java.lang.Throwable stack = new java.lang.Throwable();
	java.lang.StackTraceElement stacktrace = null;

	stacktrace = stack.getStackTrace()[1];

	if (stacktrace.getFileName() != null) {
	    strbuf.append(stacktrace.getFileName());
	    if (stacktrace.getLineNumber() != -1) {
		strbuf.append(":");
		strbuf.append(stacktrace.getLineNumber());
	    }
	    strbuf.append(" ");
	}
	strbuf.append(stacktrace.getClassName());
	strbuf.append(".");
	strbuf.append(stacktrace.getMethodName());
	strbuf.append("()");
	if (msg != null) {
	    strbuf.append(" ");
	    strbuf.append(msg);
	}
	Logger.getLogger("org.debian.paulliu").log(level, strbuf.toString());
    }

    public static void main(String[] args)
    {
	org.debian.paulliu.plft.Session session = new org.debian.paulliu.plft.Session();
	PLFT.log(Level.INFO, "PLFT main start");
	PLFT.log(Level.INFO, "My Socket: "+session.getStunClient().getMyPublicIP()+":"+Integer.toString(session.getStunClient().getMyPublicPort()) + "(" +session.getStunClient().getMyPrivateIP()+":"+Integer.toString(session.getStunClient().getMyPrivatePort()) + ")" );

	PLFTWindow applet = new PLFTWindow(session);

	JFrame frame = new JFrame("PLFT");
	frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });
	frame.getContentPane().add(applet);
	frame.setSize(600,400);
	applet.setParentFrame(frame);
	applet.init();
	applet.start();
	frame.setVisible(true);
    }
}
